import time

import page
from base.base import Base


class PageBackOrder(Base):
    # 一级标题：订单
    def page_first_level_order(self):
        self.base_click_element(page.back_first_level_order)

    # 二级标题：订单管理
    def page_second_level_order_management(self):
        self.base_click_element(page.back_second_level_order_management)

    # 二级标题：订单售后
    def page_second_level_order_aftersale(self):
        self.base_click_element(page.back_second_level_order_aftersale)

    # 商品订单-订单管理iframe
    def page_switch_to_order_manager_iframe(self):
        self.base_switch_to_iframe(page.back_order_manager_iframe)

    # # 商品订单-订单售后iframe
    def page_switch_to_order_aftersale_iframe(self):
        self.base_switch_to_iframe(page.back_order_aftersale_iframe)

    # 商品订单-快递iframe
    def page_switch_to_order_express_iframe(self):
        self.base_switch_to_iframe(page.back_order_add_express_iframe)

    # 商品订单支付
    def page_click_order_pay(self, order_id):
        self.base_click_element(page.get_order_id(order_id))

    # 商品订单支付确认
    def page_click_order_pay_submit(self):
        self.base_click_element(page.back_order_pay_submit)

    # 商品订单-添加快递按钮
    def page_click_add_express_btn(self):
        self.base_click_element(page.back_order_add_express_btn)

    # 商品订单-点击快递方式选择框
    def page_click_express_way_select(self):
        self.base_click_element(page.back_order_express_way_btn)

    # 商品订单-选择随机快递方式
    def page_select_random_express_way(self):
        self.base_click_element(page.back_order_express_way)

    # 商品订单-输入快递单号
    def page_input_express_number(self, number):
        self.base_in_element_input(page.back_order_express_number, number)

    # 商品订单-输入快递备注
    def page_input_express_note(self, note):
        self.base_in_element_input(page.back_order_express_note, note)

    # 商品订单-提交快递信息
    def page_click_express_submit(self):
        self.base_click_element(page.back_order_express_submit)
        self.base_click_element(page.back_order_submit)

    # 商品订单售后-确认申请,审核
    def page_click_aftersale_confirm_or_audit(self, aftersale_id):
        self.base_click_element(page.get_order_aftersale_id(aftersale_id))

    # 商品订单售后-选择退款方式
    def page_click_refund_way(self):
        self.base_click_element(page.back_order_express_refund_way)

    # 商品订单售后-确认退款方式
    def page_click_refund_way_submit(self):
        self.base_click_element(page.back_order_express_refund_way_submit)

    # 获得截屏
    def page_get_screenshot(self):
        self.base_get_img()

    # 回到父iframe
    def page_switch_parent_frame(self):
        self.base_switch_to_parent_frame()

    def page_order_manager(self):
        self.base_refresh()
        self.page_first_level_order()
        time.sleep(0.5)
        self.page_second_level_order_management()
        time.sleep(0.5)
        self.page_switch_to_order_manager_iframe()
        time.sleep(0.5)

    def page_order_manage_pay(self, order_id):
        self.page_click_order_pay(order_id)
        time.sleep(0.5)
        self.page_click_order_pay_submit()
        time.sleep(1)

    def page_order_manage_express(self,order_id, express_number, express_note):
        time.sleep(1)
        self.page_click_order_pay(order_id)
        time.sleep(0.5)
        self.page_switch_to_order_express_iframe()
        time.sleep(0.5)
        self.page_click_add_express_btn()
        time.sleep(0.5)
        self.page_click_express_way_select()
        self.page_select_random_express_way()
        time.sleep(0.5)
        self.page_input_express_number(express_number)
        time.sleep(0.5)
        self.page_input_express_note(express_note)
        time.sleep(0.5)
        self.page_click_express_submit()
        time.sleep(0.5)
        self.page_switch_parent_frame()
        time.sleep(1)

    def page_order_aftersale(self):
        self.base_refresh()
        self.page_first_level_order()
        time.sleep(2)
        self.page_second_level_order_aftersale()
        time.sleep(2)
        self.page_switch_to_order_aftersale_iframe()
        time.sleep(0.5)

    def page_order_aftersale_confirm(self,aftersale_id):
        self.page_click_aftersale_confirm_or_audit(aftersale_id)
        self.base_click_element(page.product_confirm_btn)
        time.sleep(0.5)

    def page_order_aftersale_audit(self,aftersale_id):
        self.page_click_aftersale_confirm_or_audit(aftersale_id)
        time.sleep(3)
        self.page_click_refund_way()
        time.sleep(2)
        self.page_click_refund_way_submit()
        time.sleep(0.5)
        self.page_switch_parent_frame()
